﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Supervise_SuperviseChillist : System.Web.UI.Page, HZ.MBSM.BLL.IPageDescribe
{
    Int64 AccountId;
    protected void Page_Load(object sender, EventArgs e)
    {
        string strBidY = "", strBidN = "", strSql;
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {

                if (_Account.Type != "1" && _Account.AccountName.Length > 0 && _Account.AccountName.Substring(0, 2) != "ZB")
                {
                    Response.Write("<script>alert('您不是招标办，无权添加子用户！');self.opener=null;self.close();</script>");
                   
                }
                AccountId = SysFun.ToLong(_Account.AccountId);

                if (!IsPostBack)
                {
                    lstType.Dispose();
                    lstType.Items.Add("日常审核");
                }
                if (Request.Form["btnSubmit"] == "授  权")
                {
                    foreach (string strId in SysFun.ToTrim(Request.Form["AccountId"]).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (SysFun.ToInt(Request.Form["radBid" + strId]) == 1)
                            strBidY = strBidY + strId + ",";
                        else
                            strBidN = strBidN + strId + ",";
                    }
                    Db db = new Db();
                    //分别授权
                    if (strBidN != "")
                    {
                        strBidN = strBidN.Substring(0, strBidN.Length - 1);
                        strSql = "update account set IsBid_Landing=0 WHERE AccountId in (" + strBidN + ") ";
                        db.Command(strSql);

                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "account", strSql, "../Agency/AgencyChildList.aspx");

                        //db.Close();
                    }
                    if (strBidY != "")
                    {
                        strBidY = strBidY.Substring(0, strBidY.Length - 1);
                        strSql = "update account set IsBid_Landing=1 WHERE AccountId in (" + strBidY + ") ";
                        db.Command(strSql);
                        //db.Close();
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "account", strSql, "../Agency/AgencyChildList.aspx");

                    }
                    db.Close();
                }

                showGridView();
            }
            else
            {
                Response.Write("<script language=JavaScript>alert('您还没有登录，暂时无权添加子用户！！！');</script>");
            }
        }
    }
    public void showGridView()
    {
        int i = 0;
        string strConditions;
        strConditions = "";
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_Account_AgencyChild ";
        dbPage.Key = "accountid";
        dbPage.Where = strConditions;
        dbPage.SelectField = "AccountId, AccountName,Pwd_Bid,case Type when '41' then '日常审核' end as type,UserName, Telephone,ZC,IsBid_Landing,UserCode";
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);
        dbPage.PageSize = 10;//Request.QueryString["PS"]);
        dbPage.OrderBy = "AccountName";
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_table'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' nowrap>用户名称</td>");
        strHtml.Append("<td class='table_title' nowrap>用户编码</td>");
        strHtml.Append("<td class='table_title' nowrap>姓名</td>");
        strHtml.Append("<td class='table_title' nowrap>密码</td>");
        strHtml.Append("<td class='table_title' nowrap>权限</td>");
        strHtml.Append("<td class='table_title' nowrap>授权</td>");
        strHtml.Append("<td class='table_title' nowrap>修改</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        while (dr.Read())
        {
            if (i == 0)
            {
                strHtml.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
                i--;
            }

            strHtml.Append("<td><input type='hidden' name='AccountId' value='" + SysFun.ToTrim(dr["accountid"]) + "'>" + dr["accountname"].ToString() + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["UserCode"]) + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["UserName"]) + "</td>");
            strHtml.Append("<td>" + SysFun.PasswordDecrypt(SysFun.ToTrim(dr["Pwd_Bid"])) + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["Type"]) + "</td>");
            strHtml.Append("<td>");
            if (SysFun.ToTrim(dr["isbid_landing"]) == "1")
            {
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='1' checked>是");
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='0'>否");
            }
            else
            {
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='1'>是");
                strHtml.Append("<input type=radio name ='radBid" + dr["accountid"].ToString() + "' value='0' checked>否");
            }
            strHtml.Append("</td>");
            strHtml.Append("<td><a target=_blank  href='SuperviseUpdate.aspx?AccountId=" + dr["accountid"].ToString() + "'>修改</a></td>");
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();
        //LabRowCount.Text = dbPage.RowCount.ToString();
        //LabPageCount.Text = dbPage.PageCount.ToString();
        //LabPageIndex.Text = dbPage.PageIndex.ToString();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;


    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp, AccountName, UserName, UserCode;
        AccountName = txtAccountName.Text.ToString().Trim();
        UserName = txtUserName.Text.ToString().Trim();
        UserCode = SysFun.ToTrim(txtUserCode.Text);
        strtemp = " AccountId_father='" + SysFun.ToTrim(AccountId) + "' and";
        switch (lstType.SelectedValue.ToString())
        {
            case "全部":
                break;
            case "配送审核":
                strtemp = strtemp + " type=41 and";
                break;
        }
        if (UserCode != "")
        {
            strtemp = strtemp + " UserCode like '%" + UserCode + "%' and";
        }
        if (AccountName != "")
        {
            strtemp = strtemp + " AccountName like '%" + AccountName + "%' and";
        }
        if (UserName != "")
        {
            strtemp = strtemp + " UserName like '%" + UserName + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }


    #region IPageDescribe 成员

    public string Name
    {
        get { return "子用户管理"; }
    }

    public string Describe
    {
        get { return "子用户管理"; }
    }

    public string ParentName
    {
        get { return "子用户管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
            return _AccountType;
        }
    }

    #endregion
}

